package com.example.hssmgs.Teacher;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.hssmgs.MainActivity;
import com.example.hssmgs.R;
import com.example.hssmgs.Student.CommonDatabase;

public class Teacher_login extends AppCompatActivity {
    private Button teacher_show_info;
    private Button look_left_msg;
    private Button back_Main_2;
    private TextView msg;
    private String teacher_id;
    private SQLiteDatabase db;


    @SuppressLint("Range")
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.teacher_login);

        initView();

        // 获取用户信息
        final Intent about_me_intent = getIntent();
        teacher_id = about_me_intent.getStringExtra("teacher_id");
        //获取数据库对象
        db = new CommonDatabase().getSqliteObject(Teacher_login.this, "test2.db");
        String teacher_name="";
        @SuppressLint("Recycle") Cursor cursor_about = db.query("teacher_db",null,"id=?",new String[]{teacher_id},null,null,null);
        while(cursor_about.moveToNext())
        {
            //将通过id查询到的教师信息显示到界面中
            teacher_name=cursor_about.getString(cursor_about.getColumnIndex("name"));
        }
//        TextView t_about_account = findViewById(R.id.show_t_account);
//        TextView t_about_id = findViewById(R.id.show_t_id);
        String str = "你好 "+teacher_name+"老师，工号 "+teacher_id;
        msg.setText(str);
//
//        @SuppressLint("Recycle") Cursor cursor_about = db.query("teacher_db",null,"account = ?",new String[]{about_me_intent.getStringExtra("teacher_id")},null,null,null);
//        while(cursor_about.moveToNext())
//        {
//            //将通过id查询到的教师信息显示到界面中
//            t_about_account.setText(cursor_about.getString(cursor_about.getColumnIndex("account")));
//            t_about_id.setText(cursor_about.getString(cursor_about.getColumnIndex("id")));
//        }


        teacher_show_info.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(Teacher_login.this, Teacher_look_stu.class);
                startActivity(intent);
            }
        });

        look_left_msg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(Teacher_login.this, Teacher_look_msg.class);
                intent.putExtra("teacher_id", teacher_id);
                startActivity(intent);
            }
        });

        back_Main_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initView() {
        teacher_show_info = findViewById(R.id.teacher_show_info);
        look_left_msg = findViewById(R.id.look_left_msg);
        back_Main_2 = findViewById(R.id.back_Main_2);
        msg = findViewById(R.id.show_msg_t);
    }
}